<template>
  <div class="panel"
       v-loading="loading"
       element-loading-text="拼命加载中"
       element-loading-spinner="el-icon-loading"
  >
    <panel-title title="受众列表"></panel-title>
    <div class="panel-body">
      <!--搜索框-->
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="">
          <el-input v-model="searchNickname" placeholder="昵称"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="searchCrawlDate" type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            align="right">
          </el-date-picker>
        </el-form-item>
        <el-button @click="cleanSearch"><i class="fa el-icon-close"></i>&nbsp;清空</el-button>
        <el-button type="primary" @click="getReviewerPageData"><i class="fa fa-search"></i>&nbsp;查询</el-button>
        <!--<el-button type="warning" @click="exportExcel"><i class="fa fa-download"></i>&nbsp;导出</el-button>-->
      </el-form>
      <el-table
        size="mini"
        :data="clients.data"
        border
        style="width: 100%"
      >
        <el-table-column
          prop="reviewerId"
          label="用户ID"
          width="150px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="nickname"
          label="用户昵称"
          width="180px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="sex"
          label="性别"
          width="80px"
          align="center"
        >
        <template slot-scope="scope">
          {{sexFormat(scope.row.sex)}}
          </template>
        </el-table-column>
        <el-table-column
          prop="resume"
          label="简介"
          width="250px"
          align="center"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          prop="url"
          label="主页"
          width="80px"
          align="center"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="openNewPage(scope.row.url)">查看主页</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="crawlDate"
          label="时间"
          align="center"
          :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{dateFormat(scope.row.crawlDate)}}
          </template>
        </el-table-column>
        <!-- <el-table-column
          fixed="right"
          label="操作"
          align="center"
          width="80px"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="jumpToReviewerDetail(scope.row.reviewerId)">分析</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="clients.pageNo"
          :page-sizes="[10, 50, 100, 200]"
          :page-size="clients.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="clients.total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
  import soldsChart from '../../components/chart/soldsChart'
  import {panelTitle} from 'components'
  import moment from 'moment'

  export default {
    data() {
      return {
        clients: {
          total: 0,
          pageSize: 10,
          currentPageNo: 1,
          data: []
        },
        searchNickname: null,
        searchCrawlDate: [],
        searchSentiment: null,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }],
        },
        loading: false
      }
    },
    components: {
      soldsChart,
      panelTitle
    },
    created() {
      this.getReviewerPageData()
    },
    methods: {
      //获取数据
      getReviewerPageData() {
        this.loading = true
        this.$fetch.apiReviewer.getReviewers({
          //查询参数
          pageSize: this.clients.pageSize,
          pageNo: this.clients.pageNo,
          nickname: this.searchNickname,
          startDate: this.searchCrawlDate[0],
          endDate: this.searchCrawlDate[1],
        }).then(({data: data}) => {
          this.clients = data
          this.loading = false
        })
      },

      handleClick(row) {
        alert("主图")
        console.log(row);
      },
      handleSizeChange(val) {
        this.clients.pageSize = val
        this.getReviewerPageData()
      },
      handleCurrentChange(val) {
        this.clients.pageNo = val
        this.getReviewerPageData()
      },
      openNewPage(url) {
        window.open(url)
      },
      sexFormat(sex) {
        if(sex == 1) {
          return '男'
        }
        else {
          return '女'
        }
      },
      dateFormat(dateTime) {
        if (dateTime == undefined) {
          return "";
        }
        return moment(dateTime).format("YYYY-MM-DD HH:mm:ss");
      },
      jumpToReviewerDetail(id) {
        this.$router.push({
          name: 'reviewerDetail',
          params: {id: id}
        })
      },
      cleanSearch() {
        this.searchNickname = null
        this.searchSentiment = null
        this.searchCrawlDate = []
      },
    },
  }
</script>

<style>
  .el-row {
    margin-bottom: 20px;
  }

  .line-limit-length {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
</style>
